package com.colabo.j2ee.web.oaf.security;

import java.util.Date;
import java.util.List;

import com.colabo.j2ee.web.core.exception.ServiceException;
import com.colabo.j2ee.web.core.vo.RecordObject;
import com.colabo.j2ee.web.oaf.orgnization.model.SCUserProfileVO;
import com.colabo.j2ee.web.oaf.security.model.IPArcChannelVO;

/**
 * 这个接口用于对用户进行授权和对用户权限进行编辑
 */
public interface IGrantService {
	String BEAN_ID = "grantService";

	public int getAllGrantsCount() throws ServiceException;

	public List getAllGrants(int offset, int pageSize) throws ServiceException;

	/**
	 * 自定义权限查询, 可以根据principal类型查权限, 根据principal对象查权限,
	 * 根据resource类型查权限以及根据resource对象查权限. 另外本方法还可以根据channel查权限以及通过权限有效期查权限
	 */
	public List getGrants(Class principalClass, RecordObject principal, Class targetClass, RecordObject target,
			IPArcChannelVO channel, Date date, int offset, int pageSize) throws ServiceException;

	/**
	 * 返回通过条件查询的权限总数, 用于分页显示权限列表时显示权限总数
	 */
	public int getGrantCount(Class principalClass, RecordObject principal, Class resourceClass, RecordObject resource,
			IPArcChannelVO channel, Date date) throws ServiceException;

	/**
	 * 取当前岗位权限, 用于授权时显示当前岗位已授予权限
	 */
	public List getGrantsByPrincipal(RecordObject principal, Class resourceClass, IPArcChannelVO channel, Date date,
			int offset, int pageSize) throws ServiceException;

	public List getGrantsByPrincipal(RecordObject principal, Class resourceClass, IPArcChannelVO channel, Date date)
			throws ServiceException;

	/**
	 * 取当前岗位权限总数
	 */
	public int getGrantCountByPrincipal(RecordObject principal, Class resourceClass, IPArcChannelVO channel, Date date)
			throws ServiceException;

	/**
	 * 取用户全部权限, 用于根据人员进行权限查询, 比如取得某用户所有菜单权限则可以通过以下方法获得: <br>
	 * SCUserProfileVO staff=staffService.getStaffByStaffId("staffid"); <br>
	 * List l=getAllGrantsByStaff(staff, IPResMenuVO.class, null, null, 0,
	 * 9999);
	 */
	public List getAllGrantsByStaff(SCUserProfileVO staff, Class resourceClass, IPArcChannelVO channel, Date date,
			int offset, int pageSize) throws ServiceException;

	public List getAllGrantsByStaff(SCUserProfileVO staff, Class resourceClass, IPArcChannelVO channel, Date date)
			throws ServiceException;

	/**
	 * 用户全部权限总数, 可以对权限类型进行过滤, 对channel过滤以及对日期过滤
	 */
	public int getAllGrantCountByStaff(SCUserProfileVO staff, Class resourceClass, IPArcChannelVO channel, Date date)
			throws ServiceException;

	/**
	 * 根据员工对象取员工拥有的权限并且通过ResRelation取得这些资源关联的其他资源对象. 这个方法用于用户登录时获取用户所有权限.
	 */
	public List getAllGrantsWithRelatedResourceByStaff(SCUserProfileVO staff, IPArcChannelVO channel, Date date)
			throws ServiceException;

	/**
	 * 根据资源查询拥有该资源权限的对象, 比如查找拥有某菜单权限的所有岗位: <br>
	 * IPResMenuVO menu=menuService.getMenuByMenuCode("menuCode"); <br>
	 * List l=getPrincipalGrantsByResource(menu, null, 0, 9999);
	 */
	public List getPrincipalGrantsByResource(RecordObject resource, IPArcChannelVO channel, int offset, int pageSize)
			throws ServiceException;

	public int getPrincipalGrantCountByResource(RecordObject resource, IPArcChannelVO channel) throws ServiceException;

	/**
	 * 根据资源查询拥有该资源权限的人员
	 */
	public List getAllGrantedStaffsByResource(RecordObject resource, IPArcChannelVO channel, int offset, int pageSize)
			throws ServiceException;

	public int getAllGrantedStaffCountByResource(RecordObject resource, IPArcChannelVO channel) throws ServiceException;

	/**
	 * 保存资源权限, 这个方法将insertBeans中的资源授予principal,
	 * 并将deleteBeans中的资源权限从principal权限中删除
	 * 
	 * @param principal
	 *            授权载体
	 * @param insertBeans
	 *            新增权限对象 List<ValueObject>
	 * @param deleteBeans
	 *            删除权限对象 List<ValueObject>
	 * @throws ServiceException
	 */
	public void batchCommit(RecordObject principal, List insertBeans, List deleteBeans) throws ServiceException;

	/**
	 * 根据参数删除权限, 若全为null则删除所有权限
	 */
	public void deleteGrants(Class principalClass, RecordObject principal, Class resourceType, RecordObject resource,
			IPArcChannelVO channel) throws ServiceException;

	/**
	 * 判断是否超级管理员, 管理员拥有全部系统权限
	 */
	public boolean isAdmin(String username) throws ServiceException;
	
	/**
	 * 获取菜单编码列表
	 * @param code 岗位ID，列表用逗号分隔
	 * @return
	 * @throws ServiceException
	 */	
	List getMenuCodeList(String code) throws ServiceException;
	
	/**
	 * 获取URL列表
	 * @param code 岗位ID，列表用逗号分隔
	 * @return
	 * @throws ServiceException
	 */
	List getUrlList(String code) throws ServiceException;
	
	/**
	 * 获取功能列表
	 * @param code 岗位ID，列表用逗号分隔
	 * @return
	 * @throws ServiceException
	 */
	List getFunctionList(String code)throws ServiceException;
}
